package com.jfinal.ext.plugin.memcache;

import net.dreamlu.config.Consts;

import com.baidu.bae.api.factory.BaeFactory;
import com.baidu.bae.api.memcache.BaeCache;
import com.jfinal.plugin.IPlugin;

/**
 * MCachePlugin
 * @author l.cm
 *
 */
public class MCachePlugin implements IPlugin {
	
	private static BaeCache memcache;

	public MCachePlugin() {}

	@Override
	public boolean start() {
		createCacheManager();
		MCacheKit.init(memcache);
		return true;
	}

	@Override
	public boolean stop() {
		memcache = null;
		return true;
	}


	private void createCacheManager() {
		if (memcache != null) {
			return;
		} else {
			memcache = BaeFactory.getBaeCache(Consts.CACHEID, Consts.MEMCACHEADDR, Consts.AK, Consts.SK);
		}
	}
}
